var app=getApp();
Page({

  data: {
  
  },

  onLoad: function (options) {
  this.setData({
    userInfo: app.globalData.g_userInfo
  })
  },
  showModal:function(title,content,callback){
    wx.showModal({
      title:title,
      content:content,
      confirmColor:'#1F4BA5',
      cancelColor:'#7F8389',
      success:function(res){
        if(res.confirm){
          callback&&callback()
        }
      }
    })
  },
  clear:function(){
    this.showModal('缓存清理','确定要清除本地缓存吗？',function(){
      wx.clearStorage({
        success:function(msg){
          wx.showToast({
            title: '缓存清理成功',
            duration:1000,
            mask:true,
            icon:'success'
          })
        }
      })
    })
  },
  info:function(){
    wx.navigateTo({
      url: 'device/device',
    })
  },
  showNet:function(){
    var self=this;
    wx.getNetworkType({
      success: function(res) {
        var networkType=res.networkType
        self.showModal('网络状态','您当前的网络：'+networkType)
      },
    })
  },
  showLon:function(){
    var self=this;
    this.getLon(function(lon,lat,speed){
      var lonStr=lon>=0?'东经':'西经';
      var latStr=lat>=0?'北纬':'南纬';
      lon=lon.toFixed(2);
      lat=lat.toFixed(2);
      lonStr+=lon;
      latStr+=lat;
      speed=(speed||0).toFixed(2);
      self.showModal('当前位置和速度', '当前位置：' + lonStr + ',' + latStr + '。速度:' + speed + 'm/s')
    })
  },
  getLon:function(callback){
    var self=this;
    wx.getLocation({
      success: function(res) {
        callback(res.longitude,res.latitude,res.speed)
      },
    })
  },
  showMap:function(){
    this.getLon(function(lon,lat){
      wx.openLocation({
        latitude: lat,
        longitude: lon,
      })
    })
  },
scan:function(){
  var self=this;
  wx.scanCode({
    success:function(res){
      self.showModal('扫描二维码',res.result,false)
    }
  })
}
})